<template>
	<view class="padding-xl">
		<!-- <image src="/static/bbb.jpg" mode="scaleToFill" style="height: 500upx;width: 100%;"></image> -->
		<view class="grid-box">
			<view class="ele box1"  @click="toDetail">
			<!-- 	<image src="../../static/a1.png" mode="aspectFit" style="width: 150upx; height: 150upx;"></image>
				<view>
					<view>累计邀请人数</view>
					<view class="red">{{count}}人</view>
				</view> -->
			</view>
			<view class="ele box2">
				 <image :src="codeUrl" style="width: 150upx; height: 150upx;" mode="aspectFit"></image>
				 <view>分享二维码</view>
			</view>
			<button class="ele box3" open-type="share" >
				<image src="../../static/a2.png" style="width: 150upx; height: 150upx;" mode="aspectFit"></image>
				<view>链接分享</view>
			</button>
		</view>
		

	</view>
</template>

<script>
	import {
		getShareCode,
		getUserInfo
	} from '@/api'
	export default {
		props: {
			count: Number,
			codeUrl: String,
		},
		onShareAppMessage() {
			return {
				title: '预约咨询',
				path: 'pages/index/index?scene=' + this.inviteCode, // 分享页面的路径
				imageUrl: '../../static/banner.jpg', // 分享图片的链接
			};
		},
		data() {
			return {
				inviteCode: '',
				code: '1160548SX2855',
				isLogin: false, //是否已登录
			};
		},
		methods: {
			toDetail() {
				this.$emit('showDetail')
			},
			save() {
				let base64Image = this.codeUrl;
				// 去除 base64 编码中的头部信息，如 "data:image/jpeg;base64,"
				const base64Data = base64Image.replace(/^data:image\/\w+;base64,/, "");
				// 生成临时文件名
				const fileName = `temp-${Date.now()}.png`;
				// 写入临时文件
				wx.getFileSystemManager().writeFile({
					filePath: `${wx.env.USER_DATA_PATH}/${fileName}`,
					data: base64Data,
					encoding: "base64",
					success: () => {
						// 保存图片到相册
						wx.saveImageToPhotosAlbum({
							filePath: `${wx.env.USER_DATA_PATH}/${fileName}`,
							success: (res) => {
								uni.showToast({
									icon: 'success',
									title: '保存成功'
								})
								console.log("保存成功", res);
							},
							fail: (err) => {
								console.error("保存失败", err);
							},
						});
					},
					fail: (err) => {
						console.error("写入临时文件失败", err);
					},
				});
			},
			// 去会员中心
			toVip() {
				uni.showToast({
					title: '去会员中心',
					icon: 'none',
					duration: 2000
				});
				console.log('跳去vip');
			},
			//复制
			fuzhi() {
				uni.setClipboardData({
					data: this.code,
					success: function() {
						uni.showToast({
							title: '已复制',
							icon: 'success',
							duration: 2000
						});
					}
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
	.padding-xl {
		min-height: 100vh;
		background: #F7F7F7;
	}
	.grid-box {
		display: grid;
		grid-template-columns: repeat(4, 1fr);
		grid-template-rows: repeat(1, 1fr);
		grid-column-gap: 10px;
		grid-row-gap: 10px;
		padding: 10px;
		position: fixed;
		bottom: 10upx;
		width: calc(100vw - 20upx);
		.ele {
			height: 200upx;
			background-color: #fff;
		}
		.box1 { 
			grid-area: 1 / 1 / 2 / 5; 
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 26upx;
			text-align: center;
			.red {
				color: red;
			}
		}
		.box2 { 
			grid-area: 1 / 1 / 3 / 3; 
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 26upx;
			flex-direction: column;
		}
		.box3::after {
			border: none;
		}
		.box3 { 
			display: block;
			width: 100%;
			border: none;
			grid-area: 1 / 3 / 3 / 5; 
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 26upx;
			flex-direction: column;
		}
	}
	
	.padding-tb-sm {
		padding-top: 20upx;
		padding-bottom: 20upx;
	}

	.padding-xl {
	}

	.padding-sm {
		padding: 20upx;
	}

	.flex {
		display: flex;
	}

	.justify-center {
		justify-content: center;
	}

	.justify-between {
		justify-content: space-between;
	}

	.align-end {
		align-items: flex-end;
	}

	.align-center {
		align-items: center;
	}

	.text-bold {
		font-weight: bold;
	}


	.textList {
		margin-top: 80rpx;
		position: relative;
		z-index: 3;
	}

	.text-1 {
		font-size: 40rpx;
	}

	.text-2 {
		font-size: 50rpx;
		font-weight: bold;
		padding: 10rpx 0;
	}

	.text-3 {
		padding: 7rpx;
		border-radius: 20rpx;
		margin-top: 10rpx;
		width: 330rpx;
		display: flex;
		justify-content: center;
		border: 1px solid #555555;
		color: #555555;
	}

	.logoimg {
		position: absolute;
		right: 20rpx;
		top: 0rpx;
		z-index: 1;
	}

	.kuai {
		border-radius: 35rpx;
		box-shadow: 0 2rpx 5rpx 2rpx #bcbcbc;
	}

	.xian {
		height: 1px;
		background-color: #efefef;
	}

	.yqm {
		background-color: #383c3f;
		// border: 1px solid #313131;
		border-radius: 30rpx;
		color: #fff;
	}

	.fuzhi {
		padding: 7rpx 20rpx;
		border: 1px solid #fafafa;
		border-radius: 20rpx;
		margin-left: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #fff;

	}

	.huiyuan_btn {
		background-color: #383c3f;
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
		color: #ffffff;
	}

	.btn_list {
		padding: 40rpx 0;
		display: flex;
		justify-content: space-around;
	}

	.btn1 {
		border-radius: 40rpx;
		text-align: center;
		background-color: #dbedf9;
		padding: 25rpx 0;
		font-weight: bold;
		box-shadow: 0 1rpx 10rpx 2rpx #b8b8b8;
		color: #5f5f5f;
		line-height: 1;
	}

	.btnAction {
		// background: linear-gradient(90deg, #C8F677 2.1%, #9AED86 99.87%);
		background: linear-gradient(to right, rgb(205, 76, 8), rgb(230, 13, 20));
		color: #ffffff;

	}

	.biaoshi {
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #383c3f;
		margin-right: 10rpx;
		font-size: 20rpx;
	}

	.text-hui {
		color: #565656;
		padding: 5rpx 0;
		font-size: 23rpx;
	}
</style>